package com.wn.procurement.web;

import com.wn.common.PageBean;
import com.wn.common.ResponseEntity;
import com.wn.entity.Material;
import com.wn.procurement.service.MaterialService;
import com.wn.procurement.vo.MaterialVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/material")
public class MaterialController {

    @Autowired
    private MaterialService materialService;

    @RequestMapping("/add")
    public ResponseEntity add(@RequestBody @Validated Material material){
        materialService.insert(material);
        return ResponseEntity.success;
    }

    @RequestMapping("/update")
    public ResponseEntity update(@RequestBody @Validated Material material){
        materialService.update(material);
        return ResponseEntity.success;
    }

    @RequestMapping("/query")
    public ResponseEntity query(@RequestBody  MaterialVo material){
        PageBean<Material> pageBean = materialService.getByCondition(material);
        return new ResponseEntity(pageBean);
    }
}
